using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Oops.Xna.Framework.Physics;

namespace Oops.Xna.Framework.Testing.App
{
	public class Example2Screen : ExampleScreen
	{
		public Example2Screen(Game game) : base(game, "Example2") {	}

		#region ExampleScreen Members

		protected override void DrawWorld(Effect effect, EffectParameter world, EffectParameter texture)
		{
			
		}

		protected override void Reset()
		{
			// Start with 50 boxes and 150 spheres.
			this.Reset(0, 200);

			this.physics.Speed = 1.0f;

			// Create the collision group.
			CollisionGroup collisionGroup = new CollisionGroup();

			// Create the floor box.
			CollisionBox box = new CollisionBox();
			box.Extents = new Vector3(110.0f, 5.0f, 110.0f);
			box.OffsetPosition = Vector3.Down * 110.0f;
			collisionGroup.CollisionShapes.Add(box);
			this.boxes.Add(box);

			// Create the back box.
			box = new CollisionBox();
			box.Extents = new Vector3(110.0f, 110.0f, 5.0f);
			box.OffsetPosition = Vector3.Forward * 110.0f;
			collisionGroup.CollisionShapes.Add(box);
			this.boxes.Add(box);

			// Create the front box.
			box = new CollisionBox();
			box.Extents = new Vector3(110.0f, 110.0f, 5.0f);
			box.OffsetPosition = Vector3.Backward * 110.0f;
			collisionGroup.CollisionShapes.Add(box);
			this.boxes.Add(box);

			// Create the left box.
			box = new CollisionBox();
			box.Extents = new Vector3(5.0f, 110.0f, 110.0f);
			box.OffsetPosition = Vector3.Left * 110.0f;
			collisionGroup.CollisionShapes.Add(box);
			this.boxes.Add(box);

			// Create the front box.
			box = new CollisionBox();
			box.Extents = new Vector3(5.0f, 110.0f, 110.0f);
			box.OffsetPosition = Vector3.Right * 110.0f;
			collisionGroup.CollisionShapes.Add(box);
			this.boxes.Add(box);

			Vector3 position = Vector3.Down * 150.0f;
			collisionGroup.UpdateTransform(ref position);

			// Change all the sphere's radii.
			for (int i = 0; i < this.spheres.Count; i++)
			{
				this.spheres[i].Radius = 16.0f;
			}
			// Recalculate the mass properties and modify the gravity.
			for (int i = 0; i < this.physics.RigidBodies.Count; i++)
			{
				this.physics.RigidBodies[i].Acceleration = Vector3.Down * 25.0f;
				this.physics.RigidBodies[i].CalculateMassProperties(1.0f);
			}

			// Add the plane's collision group to the collision system.
			this.physics.CollisionSystem.CollisionGroups.Add(collisionGroup);
		}

		#endregion
	}
}
